package com.atguigu.spzx.controller;

import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.model.vo.h5.IndexVo;
import com.atguigu.spzx.service.CategoryService;
import com.atguigu.spzx.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/product/index")
//@CrossOrigin
public class IndexController{

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ProductService productService;

    @GetMapping()
    public Result index(){
        List<Category> list = categoryService.selectOne();
        List<ProductSku> list2 = productService.selectSkuBySal();
        IndexVo indexVo = new IndexVo();
        indexVo.setCategoryList(list);
        indexVo.setProductSkuList(list2);
        return Result.build(indexVo, ResultCodeEnum.SUCCESS);
    }

}